﻿using Bangle.BLL;
using Bangle.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Main_NodeEdit : BasePage
{
    T_Node model = new T_Node();
    T_NodeBLL bll = new T_NodeBLL();

    #region 属性
    /// <summary>
    /// Guid
    /// </summary>
    private Guid NodeId
    {
        get
        {
            return Request.QueryString["NodeId"] == null ? Guid.Empty : Guid.Parse(Request.QueryString["NodeId"].ToString());
        }
    }

    /// <summary>
    /// Action
    /// </summary>
    public string Action
    {
        get
        {
            return Request.QueryString["Action"] == null ? "Add" : Request.QueryString["Action"].ToString();
        }
    }
    #endregion

    #region 加载
    protected void Page_Load(object sender, EventArgs e)
    {
        setUserControlStatus();
        if (!IsPostBack)
        {
            getDate();
        }
    }
    #endregion

    #region 检验用户权限
    private void setUserControlStatus()
    {
        //检验用户权限
        //base.CheckUserPermission("002002");
    }
    #endregion

    #region 绑定数据

    /// <summary>
    /// 加载数据
    /// </summary>
    /// <param name="id"></param>
    private void getDate()
    {
        model = bll.GetModel(NodeId);
        if (model == null)
        {
            return;
        }
        this.txt_Content.Text = model.Content;
    }
    #endregion

    #region 提交
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        if (Action == "Modify")
        {
            model = bll.GetModel(NodeId);
        }
        else if (Action == "Add")
        {
            model = new T_Node();
        }

        model.Content = this.txt_Content.Text;
        model.UpdateTime = BasePage.GetNowTimeString();
        model.UpdateUserId = BasePage.CurrentSession2.UserID;
        model.OrderTime = model.UpdateTime;

        try
        {
            if (Action == "Modify")
            {
                //修改
                bll.Update(model);
            }
            else if (Action == "Add")
            {
                model.CreateTime = model.UpdateTime;
                model.CreateUserId = model.UpdateUserId;
                model.NodeId = Guid.NewGuid();
                model.Valid = 1;

                //保存
                bll.Add(model);
            }
            base.CloseWindowAndRefresh();
        }
        catch (Exception ex)
        {
            base.AlertError(ex.ToString());
        }
    }
    #endregion
}